package com.hex.es.service.impl;

import com.github.vanroy.springdata.jest.JestElasticsearchTemplate;
import com.hex.es.annotation.EsBuildParamTypeInfo;
import com.hex.es.service.ReturnSearchInterface;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.elasticsearch.core.query.SearchQuery;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.lang.reflect.Method;
import java.util.List;

/**
 * @description: List返回类型处理类
 * @author: Hex
 * @date: 2019/11/13 16:29
 */
@Slf4j
@Service
public class ReturnListImpl implements ReturnSearchInterface {

    @Resource
    private JestElasticsearchTemplate jestElasticsearchTemplate;

    @Override
    public Object search(Method method, EsBuildParamTypeInfo esBuildParamTypeInfo, SearchQuery searchQuery) {
        return jestElasticsearchTemplate.queryForList(searchQuery,esBuildParamTypeInfo.resultType());
    }

    @Override
    public Boolean check(Method method, EsBuildParamTypeInfo esBuildParamTypeInfo) {
        return List.class.equals(method.getReturnType());
    }

    @Override
    public int getOrder() {
        return 5;
    }
}
